﻿using System;
using System.Collections.Generic;
using System.Text;
using Tauren.Business.DLL.Base;
using Tauren.Business.DLL.TableInfoDLL;
using Tauren.Business.DLL.Resouces;
using Tauren.Business.Entity.Config;
using Tauren.Business.Entity.Const;
using Tauren.Business.Entity.Enum;
using Tauren.Business.Entity.Global;
using Tauren.Business.Entity.Input;
using Tauren.Business.Entity.Model;
using Tauren.Business.Infrastructure.Globals;
using System.Linq;
using System.Transactions;
using Tauren.Business.Entity.Output;

namespace Tauren.Business.Service.TableInfoBLL
{
    /// <summary>
    /// 字典
    /// </summary>
    public class TableInfoService : Base.BaseService, ITableInfoService
    {
        private ITableInfoBusiness business;
        public TableInfoService(ITableInfoBusiness _business, IConnectionBLLBase connectionBLL, IMenuResourcesBusiness resourcesBusiness) : base(_business, connectionBLL, resourcesBusiness)
        {
            this.business = _business;
            this.ResourcesInfo = this.GetResources(GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY);
            this.JudePrmission(GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower());
        }

        public IResponseMessage Add(Tableinfo_IntPut data)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA));
            var codes = business.IsPermissionCodeRepeat(0, data.TableCode);
            if (codes) return GlobalErrorType.GLOBAL_REPEAT_CODE.Failure(this.CommonText(GlobalErrorType.GLOBAL_REPEAT_CODE));
            TableInfo Tableinfo;
            ToModel(data, out Tableinfo);
            Tableinfo.Enable = true;
            Tableinfo.HaveDelete = false;
            Tableinfo.Sequence = business.GetSeq();
            Tableinfo.Creator = this.Global.EmpId;
            Tableinfo.Modifier = this.Global.EmpId;
            Tableinfo.Creatdate = DateTime.Now;
            Tableinfo.Modifdate = DateTime.Now;
            if (Tableinfo.IsFlow.Value) Tableinfo.FlowTableCode = $"{Tableinfo.TableCode}apply";
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                bool b = false;
                if (data.Tables.Any())
                {
                    Tableinfo.PkTable = data.Tables.FirstOrDefault().TableCode;
                }
                long id = business.Add(Tableinfo);
                if (id > 0)
                {
                    b = business.CreateTbale(Tableinfo);
                }
                if (b)
                {
                    ts.Complete();
                    return "".OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_SUCCESSINFO.ToString()));
                }
                else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));
            }
        }

        public IResponseMessage Config(string PageType)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<OutPutConfig> Fields = new List<OutPutConfig>();

            OutPutConfig config = new OutPutConfig();
            config.Label = this.CommonText("thcode");
            config.FieldKey = "tableCode";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view" && PageType != "edit";
            config.Required = PageType != "view" && PageType != "edit";
            Dictionary<object, object> rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                #region 添加验证规则

                rule.Add("required", true);
                rule.Add("message", this.Resources("coderequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 30);
                rule.Add("message", this.Resources("codemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///正则
                rule = new Dictionary<object, object>();
                rule.Add("pattern", "^([a-zA-Z0-9]){1,30}$");
                rule.Add("message", this.Resources("codedregx"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion

            #region 中文名
            config = new OutPutConfig();
            config.Label = this.CommonText("thcnname");
            config.FieldKey = "cnName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 100);
                rule.Add("message", this.Resources("cnnamemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion
            #region 英文名
            config = new OutPutConfig();
            config.Label = this.CommonText("thenname");
            config.FieldKey = "enName";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 200);
                rule.Add("message", this.Resources("ennamemax"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            #endregion     

            config = new OutPutConfig();
            config.Label = this.Resources("thgrouptype");
            config.FieldKey = "groupType";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.radio;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>() {
                new Options { Label=this.CommonText($"Dictionary{DictionaryType.emp}"),Value= DictionaryType.emp },
                new Options { Label=this.CommonText($"Dictionary{DictionaryType.org}"),Value= DictionaryType.org},
                new Options { Label=this.CommonText($"Dictionary{DictionaryType.pos}"),Value=DictionaryType.pos },
                new Options { Label=this.CommonText($"Dictionary{DictionaryType.other}"),Value=DictionaryType.other }
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);

            config = new OutPutConfig();
            config.Label = this.Resources("threcords");
            config.FieldKey = "records";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.radio;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>() {
                new Options { Label=CommonText("globalyes") ,Value= true },
                new Options { Label=CommonText("globalno") ,Value= false },
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);

            config = new OutPutConfig();
            config.Label = this.Resources("thviewtype");
            config.FieldKey = "viewType";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.radio;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Conditions.Add(new Entity.Output.Options() { Label = "records", Value = true });
            config.Options = new List<Options>() {
                new Options { Label=this.CommonText($"tbview{EnTableView.table.ToString()}"),Value= EnTableView.table },
                new Options { Label=this.CommonText($"tbview{EnTableView.form.ToString()}"),Value= EnTableView.form },
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);
            config = new OutPutConfig();
            config.Label = this.Resources("thisflow");
            config.FieldKey = "isFlow";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.radio;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>() {
                new Options { Label=CommonText("globalyes") ,Value= true },
                new Options { Label=CommonText("globalno") ,Value= false },
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);

            config = new OutPutConfig();
            config.Label = this.Resources("thsystem");
            config.FieldKey = "isSystem";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.radio;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>() {
                new Options { Label=CommonText("globalyes") ,Value= true },
                new Options { Label=CommonText("globalno") ,Value=false },
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);

            config = new OutPutConfig();
            config.Label = this.Resources("thisprimary");
            config.FieldKey = "isPrimary";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_TABLEINFO_KEY.ToLower();
            config.ControlType = ControlType.radio;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>() {
               new Options { Label=CommonText("globalyes") ,Value= true },
                new Options { Label=CommonText("globalno") ,Value= false },
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("isprimaryrequired"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);

            config = new OutPutConfig();
            config.FieldKey = "tables";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_ROLE_KEY.ToLower();
            config.ControlType = ControlType.tableinfo;
            config.Label = this.Resources("thpktable");
            config.SelectType = SelectType.radio;
            config.Show = true;
            config.Conditions.Add(new Entity.Output.Options() { Label = "isPrimary", Value = false });
            config.Editor = PageType != "view";
            config.ExceptDataField = new List<Options>() { new Entity.Output.Options() { Label = "tableCode", Value = "" } };
            config.paramters = new List<Options>() { new Entity.Output.Options() { Label = "groupType", Value = "" }, new Entity.Output.Options() { Label = "isPrimary", Value = "1", FixedValeu = true }, new Entity.Output.Options() { Label = "records", Value = "0", FixedValeu = true } };
            BuliedTableConfig(config.Tables, PageType, new List<FromTableHeader>() { new FromTableHeader { FieldKey = "tableCode", Show = false, Primary = true }, new FromTableHeader { FieldKey = "cnName" }, new FromTableHeader { FieldKey = "enName" } }, config.Operations);
            Fields.Add(config);
            return Fields.Succeed();
        }

        public IResponseMessage Delete(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            var data = business.Get<TableInfo>(AutoID);
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            data.Enable = false;
            data.HaveDelete = true;
            data.Modifier = Global.EmpId;
            data.Modifdate = DateTime.Now;
            bool b = business.Update<TableInfo>(data);
            if (b)
            {
                return "".OnSucceed(this.Resources(GlobalErrorType.GLOBAL_DELETE_SUCCESSINFO));
            }
            else return GlobalErrorType.GLOBAL_DELETE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_DELETE_FAILURE));
        }

        public IResponseMessage Edit(Tableinfo_IntPut data)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA));
            var singe = business.Get<TableInfo>(data.AutoId);
            if (singe is null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            var codes = business.IsPermissionCodeRepeat(data.AutoId, data.TableCode);
            if (codes) return GlobalErrorType.GLOBAL_REPEAT_CODE.Failure(this.CommonText(GlobalErrorType.GLOBAL_REPEAT_CODE));
            TableInfo tb;
            ToModel(data, out tb);
            tb.Sequence = singe.Sequence;
            tb.Enable = singe.Enable;
            tb.HaveDelete = singe.HaveDelete;
            tb.Creatdate = singe.Creatdate;
            tb.Creator = singe.Creator;
            tb.Modifier = this.Global.EmpId;
            tb.Modifdate = DateTime.Now;
            if (data.Tables.Any())
            {
                tb.PkTable = data.Tables.FirstOrDefault().TableCode;
            }
            else
            {
                tb.PkTable = "";
            }
            bool b = business.Update(tb);
            if (b)
                return "".OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_SUCCESSINFO.ToString()));
            else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));
        }

        public IResponseMessage Enable(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            var data = business.Get<TableInfo>(AutoID);
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            data.Enable = !data.Enable;
            data.Modifier = Global.EmpId;
            data.Modifdate = DateTime.Now;
            bool b = business.Update<TableInfo>(data);
            if (b)
            {
                return "".OnSucceed(this.CommonText(data.Enable.Value ? GlobalErrorType.GLOBAL_ENABLE_SUCCESSINFO : GlobalErrorType.GLOBAL_DISABLE_SUCCESSINFO));
            }
            else return data.Enable.Value ? GlobalErrorType.GLOBAL_ENABLE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_ENABLE_FAILURE)) : GlobalErrorType.GLOBAL_DISABLE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_DISABLE_FAILURE));
        }

        public IResponseMessage Get(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            TableInfo Tableinfo = business.Get<TableInfo>(AutoID);
            Tableinfo_OutPut _OutPut = new Tableinfo_OutPut() { ViewType = (int)EnTableView.form, Records = false };
            if (Tableinfo != null)
            {
                ToViewModel(Tableinfo, out _OutPut);
                if (_OutPut != null)
                {
                    var tables = business.GetTableInfoByCode(_OutPut.PkTable);
                    foreach (var item in tables)
                    {
                        _OutPut.Tables.Add(new VwTableInfo_OutPut() { CNName = item.CNName, ENName = item.ENName, TableCode = item.TableCode });
                    }
                }
            }
            return _OutPut.Succeed();
        }

        public IResponseMessage Pages(QueryModel queryModel)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            TableListModel<PageTableInfoTable> tableListModel = new TableListModel<PageTableInfoTable>();
            List<TableListHeaderModele> Headers = new List<TableListHeaderModele>();
            Headers.Add(new TableListHeaderModele() { Key = "rowNo", Name = CommonText("rowNo"), Width = 50, Align = "center", Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "autoId", Name = CommonText("autoid"), Width = 70, Hide = true, Type = "primary_key", Align = "center", SorTable = SortType.custom.ToString(), Fixed = true });
            Headers.Add(new TableListHeaderModele() { Key = "tableCode", Name = CommonText("thcode"), Width = 160, Align = "left", SorTable = SortType.custom.ToString(), Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "cnName", Name = CommonText("thcnname"), Width = 220, Align = "left", IsOperation = true, SorTable = SortType.custom.ToString(), Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "enName", Name = CommonText("thenname"), Width = 220, Align = "left", SorTable = SortType.custom.ToString(), Fixed = true, Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "dic_GroupType", Name = Resources("thgrouptype"), Width = 120, Align = "center", IsTag = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_ViewType", Name = Resources("thviewtype"), Width = 120, Align = "center", IsTag = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_IsPrimary", Name = Resources("thisprimary"), Width = 120, Align = "center", IsTag = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "pkTable", Name = Resources("thpktable"), Width = 120, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_IsSystem", Name = Resources("thsystem"), Width = 120, Align = "center", IsTag = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_IsFlow", Name = Resources("thisflow"), Width = 120, Align = "center", IsTag = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Records", Name = Resources("threcords"), Width = 120, Align = "center", IsTag = true, SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Enable", Name = CommonText("thstate"), IsTag = true, Width = 100, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creator", Name = CommonText("diccreator"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creatdate", Name = CommonText("diccreatdate"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "action", Name = "操作", Width = 190, Align = "center" });
            long Total = 0;
            List<PageTableInfoTable> Data = business.Pages(queryModel, out Total);
            if (Data.Any())
            {
                Data.ForEach(o =>
                {
                    o.Dic_IsPrimary = o.IsPrimary.Value ? CommonText("globalyes") : CommonText("globalno");
                    o.Dic_IsFlow = o.IsFlow.Value ? CommonText("globalyes") : CommonText("globalno");
                    o.Dic_IsSystem = o.IsSystem.Value ? CommonText("globalyes") : CommonText("globalno");
                    o.Dic_Records = o.Records.Value ? CommonText("globalyes") : CommonText("globalno");
                    o.Dic_GroupType = this.CommonText($"dictionary{(DictionaryType)o.GroupType}");
                    o.Dic_ViewType = this.CommonText($"tbview{(EnTableView)o.ViewType}");
                    o.Dic_Enable = CommonText(o.Enable ? GlobalConst.RESOURCES_CONTENT_ENABLE_KEY : GlobalConst.RESOURCES_CONTENT_DISABLE_KEY);
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Creatdate = o.Creatdate.Value.ToString(GlobalConst.DATE_FORMAT_SECONDS);
                    o.Row_Style = o.Enable ? "" : "danger";
                    o.Operations = new List<SystemButton>();
                    if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                    {
                        BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.edit);
                        BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.field);
                        BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.detaile);
                        BuliderButtons(o.Operations, o.TableCode, o.AutoId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                        BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.delete);
                    }
                    else
                    {
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.edit.ToString()))
                            BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.edit);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.field.ToString()))
                            BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.field);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.detaile.ToString()))
                            BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.detaile);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && (o.Value == ButtomType.enable.ToString() || o.Value == ButtomType.disable.ToString())))
                            BuliderButtons(o.Operations, o.TableCode, o.AutoId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.delete.ToString()))
                            BuliderButtons(o.Operations, o.TableCode, o.AutoId, ButtomType.delete);
                    }
                });
            }
            tableListModel.Body = Data;
            tableListModel.Total = Total;
            tableListModel.Header = Headers;
            if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
            {
                BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
            }
            else
            {
                if (Buttons.Any(o => o.Value == ButtomType.add.ToString()))
                    BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
            }
            return tableListModel.Succeed();
        }

    }
}
